
#ifndef _MEMBER_BWIDGET_H_
#define _MEMBER_BWIDGET_H_

#include <BIcon>
#include <BFont>
#include <BStyle>
#include <BCursor>
#include <BLayout>
#include <BSizePolicy>
#include <BEventFilter>

#include "IState.h"
#include "IWindow.h"

#define widget_member(widget)		((member_BWidget*)((BWidget*)widget)->_ptr)

namespace BWE
{
	class BPixmap;
	class IAlignItem;

	class member_BWidget
	{
	public:
		member_BWidget(BWidget* widget);
		~member_BWidget();

		bool ignored() const;
		void freshEnabled(bool enabled);

		void clearLayer();
		void frame(GLuint msfbo, GLenum mode);
		void drawWidget(BWidget* widget, const BRect& clip, const BPoint& offset, int frameHeight);
		void takeLayout(BLayout* layout);

		void freshTitle();
		void syncWindowPos(const BPoint& wpos);
		void syncWindowSize(const BSize& wsize);

		void procEvent(const BEvent& event);

		void dispenseUpperStyles(BWidget* upper);
		void dispenseUpperStyles(BLayout* layout);
		void dispenseStyles(BEvent& event);
		void applyStyle();

		void dirtyPixmaps();
		void freshRects();
		void freshLayoutPerch();
		void adjustDirtyLayouts();

		void dirtyLayout();
		void dirtyUpperLayout();

	public:
		BWidget*				boss;
		IWindowHolder			window;
		BPixmap*				pixmap;
		BRect					absoluteRect;
		BRect					globalRect;
		BWidget*				parent;
		BWidgetHolderArray		children;

		int						samples;
		BEvent					event;
		IState					state;
		bool					refresh;
		bool					dirty;
		BByte					opacity;
		bool					layered;
		bool					resized;
		BUInt					fbo;
		BUInt					tbo;

		BIconHolder				icon;
		BString					title;
		BString					t_title;
		BString					tips;
		bool					frameless;
		bool					visible;
		bool					modal;
		bool					floating;
		bool					droppable;
		bool					focusable;
		bool					focused;
		BCursorHolder			cursor;
		BEventFilterHolder		eventFilter;

		BPoint					pos;
		BSize					size;
		BSize					minSize;
		BSize					maxSize;
		BSize					fixedSize;
		BSizePolicy				sizePolicy;

		bool					dirtyLayouts;
		BLayout*				upperLayout;
		BLayoutHolderArray		layouts;

		bool					dirtyStyle;
		BString					styleSheet;
		BStyleHolder			realStyle;
		BStyleHolder			style;

		int						border;
		BPerch					perch;
		BMargin					margin;
		IRoundHolder			round;
		BSize					radiusLeftTop;
		BSize					radiusRightTop;
		BSize					radiusLeftBottom;
		BSize					radiusRightBottom;

		bool					dirtyRects;
		BRect					rectTitle;
		BRect					rectTop;
		BRect					rectLeft;
		BRect					rectRight;
		BRect					rectBottom;
		BRect					rectCenter;
		BRect					rectLeftTop;
		BRect					rectLeftBottom;
		BRect					rectRightTop;
		BRect					rectRightBottom;

	};
}

#endif
